﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsOrderManagement
{
    //商品（商品号、单价、名字）、数量、总价格
    public class OrderDetail
    {
        public Product Product { get; set; }
        public int Quantity { get; set; }
        public decimal TotalAmount => Product.Price * Quantity;

        public OrderDetail(Product product, int quantity
          )
        {
            Product = product;
            Quantity = quantity;
        }
        public override string ToString()
        {
            return $"{Product},Quantity:{Quantity},ToatalAmount:{TotalAmount:C}";
        }
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
                return false;
            OrderDetail other = (OrderDetail)obj;
            return Product.Equals(other.Product) && Quantity == other.Quantity;
        }
        public override int GetHashCode()
        {
            return (Product, Quantity).GetHashCode();
        }


    }
}
